<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
    .container{
        width: 500px;
        height: 400px;
        border:solid 1px #ddd;
        margin: 100px auto;
    }

    #result{
        width: 100%;
        height: 300px;
    }
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class TSBan extends React.Component{
            state = {
                r: 0,
                g: 0,
                b: 0
            }
            render(){
                //解构数据
                let {r,g,b} = this.state;
                
                return <div className="container">
                        <div id="result" style={{background: `rgb(${r},${g},${b})`}}></div>
                        <hr/>
                        R: <input type="range" value={r} min="0" max="255"  onChange={this.change('r')}/>{r}<br />
                        G: <input type="range" value={g} min="0" max="255"  onChange={this.change('g')}/>{g}<br />
                        B: <input type="range" value={b} min="0" max="255"  onChange={this.change('b')}/>{b}<br />

                        <input type="text" value={`rgb(${r},${g},${b})`} />
                    </div>
            }

            change = (type) => {
                return e => {
                    this.setState({
                        [type] : e.target.value
                    })
                }
            }

        }

        ReactDOM.render(<TSBan />, document.querySelector("#root"));
    </script>
</body>
</html> 